Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/network/src/commonMain/kotlin/org/meshtastic/core/network/repository/KermitMqttLogger.kt b4bedd92fcc8d65daff79200d71f6ebc3d8f0cfa (b4bedd92) Text, 2.95 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.network.repository

Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787org.meshtastic.core.network.transport.isExpectedConnectionFailure
Tff7b72import T7ee787org.meshtastic.mqtt.MqttLogLevel
Tff7b72import T7ee787org.meshtastic.mqtt.MqttLogger

T8b949e/**
* Adapter that implements [MqttLogger] to send MQTT client logs to Kermit's [Logger].
*
* This allows the MQTTastic library logging to integrate with the app's logging infrastructure, including any
* configured log sinks (Crashlytics, Datadog, etc.).
*
* The library's [tag] (e.g. "MqttClient", "MqttConnection") is forwarded as a structured Kermit tag so that Datadog
* receives it as an indexed attribute rather than freetext in the message body, enabling per-component filtering in log
* queries.
*
* Note: The production log level should be set to [MqttLogLevel.WARN] (not INFO) to prevent the library's own
* INFO-level messages (which include endpoint addresses and topic strings) from reaching remote analytics sinks.
*/
Tff7b72class T56d364KermitMqttLoggerTb4b4b4(
T8b949e/** Base logger to tag and delegate to. Injectable so tests can capture severities. */
Tff7b72private Tff7b72val Te6edf3baseLoggerTb4b4b4: Te6edf3Logger Tff7b72= Te6edf3LoggerTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3MqttLogger Tb4b4b4{
Tff7b72override Tff7b72fun Td2a8fflogTb4b4b4(Te6edf3levelTb4b4b4: Te6edf3MqttLogLevelTb4b4b4, Te6edf3tagTb4b4b4: Tffa657StringTb4b4b4, Te6edf3messageTb4b4b4: Tffa657StringTb4b4b4, Te6edf3throwableTb4b4b4: Te6edf3Throwable?Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3logger Tff7b72= Te6edf3baseLoggerTb4b4b4.Te6edf3withTagTb4b4b4(Te6edf3tagTb4b4b4)
Tff7b72when Tb4b4b4(Te6edf3levelTb4b4b4) Tb4b4b4{
Te6edf3MqttLogLevelTb4b4b4.Te6edf3TRACE Tff7b72-Tff7b72> Te6edf3loggerTb4b4b4.Te6edf3vTb4b4b4(Te6edf3throwableTb4b4b4) Tb4b4b4{ Te6edf3message Tb4b4b4}

Te6edf3MqttLogLevelTb4b4b4.Te6edf3DEBUG Tff7b72-Tff7b72> Te6edf3loggerTb4b4b4.Te6edf3dTb4b4b4(Te6edf3throwableTb4b4b4) Tb4b4b4{ Te6edf3message Tb4b4b4}

Te6edf3MqttLogLevelTb4b4b4.Te6edf3INFO Tff7b72-Tff7b72> Te6edf3loggerTb4b4b4.Te6edf3iTb4b4b4(Te6edf3throwableTb4b4b4) Tb4b4b4{ Te6edf3message Tb4b4b4}

Te6edf3MqttLogLevelTb4b4b4.Te6edf3WARN Tff7b72-Tff7b72> Te6edf3loggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3throwableTb4b4b4) Tb4b4b4{ Te6edf3message Tb4b4b4}

T8b949e// The library logs its connection lifecycle at ERROR — broker socket close, unreachable host, Wi-Fi drop —
T8b949e// and reconnects itself; broker rejections arrive without a throwable and are user config, surfaced via
T8b949e// MqttProbeStatus. Neither is an app defect, so both log at WARN. Real faults carry a throwable.
Te6edf3MqttLogLevelTb4b4b4.Te6edf3ERROR Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3throwable Tff7b72=Tff7b72= Tff7b72null Tff7b72|Tff7b72| Te6edf3throwableTb4b4b4.Te6edf3isExpectedConnectionFailureTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3loggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3throwableTb4b4b4) Tb4b4b4{ Te6edf3message Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3loggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3throwableTb4b4b4) Tb4b4b4{ Te6edf3message Tb4b4b4}
Tb4b4b4}

Te6edf3MqttLogLevelTb4b4b4.Te6edf3NONE Tff7b72-Tff7b72> Tff7b72return
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.07s